/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edi.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.Where;
import org.joda.time.DateTime;
import org.springframework.data.domain.Auditable;

/**
 *
 * @author Kamil
 */
@Entity
@Table(name = "T_DEPARTMENTS")
@Where(clause = "DEP_AUDIT_RD IS NULL")
public class DepartmentEntity implements Auditable<Long, Long>, Serializable {

    private static final long serialVersionUID = 4169905761802955798L;

    @Id
    @SequenceGenerator(name = "department_sequence", sequenceName = "S_DEP_ID", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "department_sequence")
    @Column(name = "DEP_ID")
    private Long depId;

    @Column(length = 10, nullable = false, name = "DEP_CODE")
    private String depCode;

    @Column(length = 50, nullable = false, name = "DEP_NAME")
    private String depName;

    @OneToMany(mappedBy="udeDepartment")
    private List<DepartmentUserEntity> depUsers = new ArrayList<>();
    
    
    @Column(name = "DEP_AUDIT_CD")
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
    private DateTime createdDate;
    
    @Column(name = "DEP_AUDIT_CU")
    private Long createUser;
    
    @Column(name = "DEP_AUDIT_MD")
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
    private DateTime modifiedDate;
    
    @Column(name = "DEP_AUDIT_MU")
    private Long modifiedUser;
    
    @Column(name = "DEP_AUDIT_RD")
    @SuppressWarnings("unused")
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
    private DateTime removeDate;
    
    @Column(name = "DEP_AUDIT_RU")
    @SuppressWarnings("unused")
    private Long removeUser;
    

    public Long getDepId() {
        return depId;
    }

    public String getDepCode() {
        return depCode;
    }

    public void setDepCode(String depCode) {
        this.depCode = depCode;
    }

    public String getDepName() {
        return depName;
    }

    public void setDepName(String depName) {
        this.depName = depName;
    }

    @Override
    public boolean isNew() {
        return (depId == null);
    }

    public List<DepartmentUserEntity> getDepUsers() {
        return depUsers;
    }

    public void setDepUsers(List<DepartmentUserEntity> depUsers) {
        this.depUsers = depUsers;
    }
    
    @Override
     public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
     }

     @Override
     public boolean equals(Object o) {
        return EqualsBuilder.reflectionEquals(this, o);
     }

     @Override
     public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
     }
    
     @Override
    public Long getCreatedBy() {
      return createUser;
    }
    
    @Override
    public void setCreatedBy(Long u) {
        createUser = u;
    }

    @Override
    public org.joda.time.DateTime getCreatedDate() {
    return createdDate;
    }

    @Override
    public void setCreatedDate(org.joda.time.DateTime dt) {
       createdDate = dt;
    }

    @Override
    public Long getLastModifiedBy() {
        return modifiedUser;
    }

    @Override
    public void setLastModifiedBy(Long u) {
       modifiedUser = u;
    }

    @Override
    public org.joda.time.DateTime getLastModifiedDate() {
        return modifiedDate;
    }

    @Override
    public void setLastModifiedDate(org.joda.time.DateTime dt) {
        modifiedDate = dt;
    }
    
    public void setRemoveDate(org.joda.time.DateTime dt) {
        removeDate = dt;
    }
           
    public void setRemovedBy(Long u) {
       removeUser = u;
    }

    @Override
    public Long getId() {
        return depId;
    }
}
